package Pattern.SinglePattern.Program1;

class MainControllerCenter {
    private Menu menu;  //主控中心菜单
    private ToolBar tb;  //主控中心工具栏
    private MainForm mf;  //主控中心主窗口
    private static /*(1)*/ MainControllerCenter mcc;

    /*(2)*/
    private MainControllerCenter(){
    }


    public void init() {
        menu = new Menu();
        tb = new ToolBar();
        mf = new MainForm();
    }

    public void load() {
        menu.display();
        tb.display();
        mf.display();

    }

    public void destroy() {
        menu.destroy();
        tb.destroy();
        mf.destroy();
    }

    public static MainControllerCenter getInstance() {
        if (mcc == null) {
            mcc = new MainControllerCenter();//(3)
        }
        return mcc;
    }
}

class Test {
    public static void main(String args[]) {
        MainControllerCenter mcc1, mcc2;
        mcc1 = MainControllerCenter.getInstance();
        mcc2 = MainControllerCenter.getInstance();
        System.out.println(mcc1 == mcc2);
    }
}

class Menu{

    public void display() {
        System.out.println("Menu Display!");
    }

    public void destroy() {
        System.out.println("Menu Destroy!");
    }
}
class ToolBar{
    public void display() {
        System.out.println("ToolBar Display!");
    }

    public void destroy() {
        System.out.println("ToolBar Destroy!");
    }
}

class MainForm{

    public void display() {
        System.out.println("MainForm Display!");
    }

    public void destroy() {
        System.out.println("MainForm Destroy!");
    }
}
//其他代码省略
